package com.dnjn.happiness.biz.controller.admin;

import com.dnjn.happiness.biz.domain.AdviceTags;
import com.dnjn.happiness.biz.domain.EmotionType;
import com.dnjn.happiness.biz.domain.Training;
import com.dnjn.happiness.biz.domain.dto.StatisticalAnalysisDTO;
import com.dnjn.happiness.biz.domain.vo.StatisticalAnalysisVO;
import com.dnjn.happiness.biz.service.IAdviceService;
import com.dnjn.happiness.biz.service.IAdviceTagsService;
import com.dnjn.happiness.biz.service.IEmotionTypeService;
import com.dnjn.happiness.biz.service.ITrainingService;
import com.dnjn.happiness.biz.service.ITrainingTagsService;
import com.dnjn.happiness.biz.utils.PageUtil;
import com.dnjn.happiness.common.core.constant.SecurityConstants;
import com.dnjn.happiness.common.core.domain.R;
import com.dnjn.happiness.common.core.utils.StringUtils;
import com.dnjn.happiness.common.cloud.controller.BaseController;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.security.annotation.RequiresPermissions;
import com.dnjn.happiness.common.security.utils.SecurityUtils;
import com.dnjn.happiness.system.api.RemoteDeptService;
import com.dnjn.happiness.system.api.domain.SysDept;
import com.dnjn.happiness.system.api.domain.SysUser;
import com.dnjn.happiness.system.api.model.TreeSelectVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//统计分析
@Tag(name = "admin biz StatisticalAnalysis 统计分析", description = "统计分析")
@RestController
@RequestMapping("/admin/statistical")
public class AdminStatisticalAnalysisFirstController extends BaseController {

    @Autowired
    protected IEmotionTypeService baseService;
    @Autowired
    private IAdviceService adviceService;

    @Autowired
    private RemoteDeptService deptService;

    @Operation(summary = "第一版本-统计")
    @RequiresPermissions("biz:statistical:list")//小程序没有统计分析功能 .写的时候就加上权限了
    @PostMapping("/select")
    public AjaxResult List(@RequestBody StatisticalAnalysisDTO dto, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long deptId = user.getDeptId();
        List<StatisticalAnalysisVO> list = adviceService.selectStatistical(dto, deptId);
//        return success(list);
        return success(PageUtil.listToPage(list, current, size));

    }

    /**
     * 获取部门树列表
     */
    @RequiresPermissions("biz:statistical:list")
    @GetMapping("/deptTreeAdmin")
    public AjaxResult deptTreeAdmin(SysDept dept) {
        R<List<TreeSelectVO>> result = deptService.getDeptTreeApi(dept, SecurityConstants.INNER);
        if (StringUtils.isNotNull(result) && StringUtils.isNotNull(result.getData())) {
            return success(result.getData());
        } else {
            return success();
        }
    }



}
